package com.rm.zeyou.controller;


import com.rm.zeyou.response.ApiRestResponse;
import com.rm.zeyou.util.uploadUtil.AliOSSUtil;
import com.rm.zeyou.util.uploadUtil.OsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;

@RestController
@Api(tags = "文件上传")
@RequestMapping("/api/upload")
public class FileUploadController {
    @Resource(name = "cosServiceImpl")
    private OsService ossService;
    @Resource
    private AliOSSUtil aliOSSUtil;

    //
    // @CheckUserLogin
    // @PostMapping("/uploadFile")
    // public ApiRestResponseVO uploadFile(MultipartFile file) throws IOException {
    //     String s = ossService.uploadFile(file);
    //     return ApiRestResponseVO.success(s);
    // }
    @ApiOperation("图片上传")
    @PostMapping("uploadFile")
    public ApiRestResponse<String> uploadsss(@RequestParam MultipartFile file) throws IOException {
        //String s = UploadUtils.uploadFile(file);
        File multipartFile = aliOSSUtil.convertToFileInMemory(file);
        String s = aliOSSUtil.uploadFile(new FileInputStream(multipartFile), file.getOriginalFilename());
        //String s = JSCHUploadFile.uploadFile(file);
        return ApiRestResponse.success(s);
    }

}
